{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = 4.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "i = 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i or f are greater than 4\n"
     ]
    }
   ],
   "source": [
    "if i==1 and f > 4:\n",
    "    print(\"the value of i is 1 and f is greater than 4\")\n",
    "elif i>1 or f>4:\n",
    "    print(\"i or f are greater than 4\")\n",
    "else:\n",
    "    print(\"Both i and f are less than or equal to 4\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# loop statement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "l = [3,2,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "print(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3  \n",
      "2  \n",
      "1  \n"
     ]
    }
   ],
   "source": [
    "for e in l:\n",
    "    print(e,\" \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "counter = 6\n",
    "while counter <10:\n",
    "    print(counter)\n",
    "    counter +=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'name': 'Rick Gates', 'promoted_content': '', 'query': '%22Rick+Gates%22', 'tweet_volume': 135732, 'url': 'http://twitter.com/search?q=%22Rick+Gates%22'}, {'name': '#TheBachelorette', 'promoted_content': 'null', 'query': '%23TheBachelorette', 'tweet_volume': 91245, 'url': 'http://twitter.com/search?q=%23TheBachelorette'}, {'name': '#KremlinAnnex', 'promoted_content': 'null', 'query': '%23KremlinAnnex', 'tweet_volume': 42654, 'url': 'http://twitter.com/search?q=%23KremlinAnnex'}]\n"
     ]
    }
   ],
   "source": [
    "trends = [\n",
    "        {\n",
    "                    \"name\": \"Rick Gates\",\n",
    "                    \"promoted_content\": \"\",\n",
    "                    \"query\": \"%22Rick+Gates%22\",\n",
    "                    \"tweet_volume\": 135732,\n",
    "                    \"url\": \"http://twitter.com/search?q=%22Rick+Gates%22\"\n",
    "            },\n",
    "            {\n",
    "                    \"name\": \"#TheBachelorette\",\n",
    "                    \"promoted_content\": \"null\",\n",
    "                    \"query\": \"%23TheBachelorette\",\n",
    "                    \"tweet_volume\": 91245,\n",
    "                    \"url\": \"http://twitter.com/search?q=%23TheBachelorette\"\n",
    "            },\n",
    "            {\n",
    "                    \"name\": \"#KremlinAnnex\",\n",
    "                    \"promoted_content\": \"null\",\n",
    "                    \"query\": \"%23KremlinAnnex\",\n",
    "                    \"tweet_volume\": 42654,\n",
    "                    \"url\": \"http://twitter.com/search?q=%23KremlinAnnex\"\n",
    "            }]\n",
    "trends = sorted(trends,key = lambda e:e['tweet_volume'],reverse = True)\n",
    "print(trends)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 获取数组中指定key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "135732\n",
      "91245\n",
      "42654\n"
     ]
    }
   ],
   "source": [
    "from operator import itemgetter \n",
    "tweet_volume = map(itemgetter('tweet_volume'), trends)\n",
    "for e in tweet_volume:\n",
    "    print(e)\n",
    "# print(tweet_volume)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004,371623R30001,371623C20004,371623C20004,371623C20004,371623C20004,371623C20004\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "from operator import itemgetter\n",
    "regs_str = '[{\"name\":\"小泊头北高中心卫生室（李武元）\",\"id\":\"371623D61224\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头丁王庄卫生室（张秀玲）\",\"id\":\"371623D61227\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头马道门卫生室（马秀良）\",\"id\":\"371623D61229\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头桥王中心卫生室（李永峰）\",\"id\":\"371623D61228\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头榆树周中心卫生室（韩寿红）\",\"id\":\"371623D61223\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇北高中心卫生室\",\"id\":\"371623D60413\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇泊头街中心卫生室\",\"id\":\"371623D60412\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇菜园中心卫生室\",\"id\":\"371623D60411\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇杜家庄中心卫生室\",\"id\":\"371623D60410\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇郭马村卫生室\",\"id\":\"371623D61234\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇梁郑王中心卫生室\",\"id\":\"371623D60409\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇马道门中心卫生室\",\"id\":\"371623D60408\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇南高中心卫生室\",\"id\":\"371623D60407\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇桥王中心卫生室\",\"id\":\"371623D60406\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇筛罗坡中心卫生室\",\"id\":\"371623D60405\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇卫生院\",\"id\":\"371623C20004\",\"pId\":\"371623R30001\",\"open\":true,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇西芦中心卫生室\",\"id\":\"371623D60403\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇小田中心卫生室\",\"id\":\"371623D60402\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇榆树周中心卫生室\",\"id\":\"371623D60401\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头镇仝庄中心卫生室\",\"id\":\"371623D60404\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false},{\"name\":\"小泊头仝庄中心卫生室（梁连英）\",\"id\":\"371623D61226\",\"pId\":\"371623C20004\",\"open\":false,\"checked\":true,\"parent\":false,\"nocheck\":false}]'\n",
    "regs_str.replace(\"false\", \"False\").replace(\"true\", \"True\")\n",
    "\n",
    "regs = json.loads(regs_str)\n",
    "reg_pids = map(itemgetter('pId'), regs)\n",
    "\n",
    "reg_pids_str = \",\".join(str(x) for x in reg_pids)\n",
    "\n",
    "print(reg_pids_str)\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "73e03da126b73bfff3642ec5261d56fa25c444ea595de51041687efaa60dda41"
  },
  "kernelspec": {
   "display_name": "Python 3.8.8 64-bit ('base': conda)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
